package d0908;
import java.util.*;

public class map集合 {
    public static void main(String[] args) {
       Map<String,String> map = new HashMap<>();
        Scanner sc = new Scanner(System.in);
        map.put("名字", "元素");
        map.put("key", "value");
        map.put("武松", "行者");
        map.put("鲁智深", "花和尚");
        map.put("李忠", "打虎将");
        map.put("key", "值");
        map.put("name", "元素");
        map.put(null, null);
        map.put("空", null);

        map.forEach((key, value) -> {
            System.out.println(key + ":" + value);
        });

        // hashtable 不能有 null key
        // hashtable 线程安全==>性能低 ==> Vector
//		map = new Hashtable<>();
//		try {
//			map.put(null, null);
//		} catch (Exception e) {
//			System.out.println(e.getMessage());
//		}

        /**
         * 1.泛型固定<String,String>
         * 2.可以实现文件存储
         * 3.System.getProperties方法, 可以用于获取环境参数
         */
        Properties prop = new Properties();
        prop = System.getProperties();

        Set<Object> keys = prop.keySet();
        for (Object key : keys) {
            System.out.println("" + key + "   :   " + prop.get(key));
        }


        System.out.println("-------------------------");
        // Map集合的增强for循环
        for (  Map.Entry<String,String> o  :  map.entrySet()  ) {
            String key = o.getKey();
            String value = o.getValue();
            System.out.println(key + ":" + value);
        }

    }

}
